Skip to content

Use ThreadLocal caching for ExtendedRandom PRNG contexts#1508

Open
taoliult wants to merge 2 commits into
IBM:java25from
taoliult:java25_securerandom_native_2
Open

Use ThreadLocal caching for ExtendedRandom PRNG contexts#1508
taoliult wants to merge 2 commits into
IBM:java25from
taoliult:java25_securerandom_native_2

Conversation

@taoliult

@taoliult taoliult commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Add ThreadLocal caching for native PRNG contexts used by ExtendedRandom. Each thread creates and reuses a PRNG context for supported DRBG algorithms.

This avoids repeated EXTRAND_create calls when instances are created frequently.

Benefits:

  • Reduce native allocation overhead
  • Reuse PRNG contexts per thread
  • Improve performance in RNG-heavy workloads

This PR is back-ported from PR #1255

Add ThreadLocal caching for native PRNG contexts used by
ExtendedRandom. Each thread creates and reuses a PRNG
context for supported DRBG algorithms.

This avoids repeated EXTRAND_create calls when instances
are created frequently.

Benefits:
- Reduce native allocation overhead
- Reuse PRNG contexts per thread
- Improve performance in RNG-heavy workloads

Signed-off-by: Tao Liu <tao.liu@ibm.com>
@taoliult taoliult force-pushed the java25_securerandom_native_2 branch 2 times, most recently from 235c7da to ffb4748 Compare June 16, 2026 17:29
ThreadLocal can cause native TCB context issues on z/OS. This
change bypasses ThreadLocal on z/OS by creating instance-specific
PRNG contexts, while other platforms continue using ThreadLocal
for performance.

Signed-off-by: Tao Liu <tao.liu@ibm.com>

@KostasTsiounis KostasTsiounis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jasonkatonica jasonkatonica left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants